package com.adbj.statictest;


import com.adbj.listtest;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class TestA {

    public static void main(String[] args) throws ClassNotFoundException {
//        A a=A.getAA();
//
//        A b=A.getAA();
//
//        Thread t1=new Thread(a,"th1");

    /*    A c=A.getAA();
        c.getMessage();

        Thread t1 = new Thread(()->{
           A a= A.getAA();
            System.out.println(a);
        });
        Thread t2 = new Thread(()->{
          A a=  A.getAA();
          System.out.println(a);
        });
        t1.start();
        t2.start();
*/

        Class classA=Class.forName("com.adbj.statictest.StaticTest");
        try {
            StaticTest a= (StaticTest) classA.newInstance();
            a.say();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        Class classB=Class.forName("com.adbj.statictest.StaticTest");
        try {
           Constructor constructor=classB.getConstructor();
            try {
                StaticTest b=(StaticTest) constructor.newInstance();
                b.say();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

        StaticTest staticCode=new StaticTest();

        StaticTest ccc=staticCode


        Class aaa=Class.forName("com.adbj.listtest");
        try {
            listtest liii=(listtest) aaa.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        StaticTest h=new StaticTest();
        //准备一个文件用于存储该对象的信息
        File f = new File("StaticTest.obj");

        try
        {
            FileOutputStream fos = new FileOutputStream(f);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            FileInputStream fis = new FileInputStream(f);
            ObjectInputStream ois = new ObjectInputStream(fis);
            //序列化对象，写入到磁盘中
            oos.writeObject(h);
            //反序列化对象

            StaticTest newHello = (StaticTest)ois.readObject();

            //测试方法
            newHello.say();
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
    }
}
